package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long id);

    @Insert("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label,is_default) VALUES " +
            "(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void addAddress(AddressBook addressBook);

    @Select("select * from address_book where user_id=#{userId} and is_default=1")
    AddressBook defaultAddress(Long userId);

    @Update("update address_book set is_default=0 where user_id=#{userId}")
    void toNullDefaul(Long userId);

    @Update("update address_book set is_default=1 where id=#{id}")
    void toDafault(Long id);

    @Select("select * from address_book where id=#{id}")
    AddressBook getAddressById(Long id);

    @Update("update address_book set consignee=#{consignee},phone=#{phone},sex=#{sex},province_code=#{provinceCode},province_name=#{provinceName},city_code=#{cityCode},city_name=#{cityName},district_code=#{districtCode},district_name=#{districtName},detail=#{detail},label=#{label} where user_id=#{userId} and id=#{id} ")
    void updateAddress(AddressBook addressBook);

    @Delete("delete from address_book where id=#{id}")
    void deleteAddress(Long id);

}
